/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.classloader.observer;

import picounit.features.base.AbstractAggregateExtension;

public class AggregateClassObserver extends AbstractAggregateExtension<ClassObserver>
	implements ClassObserver {

	private ClassLoader classLoader;

	public AggregateClassObserver() {
		super(ClassObserver.class);
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// AggregateExtension methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public ClassObserver get() {
		return this;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// ClassObserver methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public void observe(byte[] byteCode) {
		for (ClassObserver classObserver : extensions()) {
			classObserver.observe(byteCode);
		}
	}

	public void setClassLoader(ClassLoader classLoader) {
		this.classLoader = classLoader;

		for (ClassObserver classObserver : extensions()) {
			classObserver.setClassLoader(classLoader);
		}
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Protected methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	@Override
	protected void add(ClassObserver extension) {
		extension.setClassLoader(classLoader);

		super.add(extension);
	}
}
